lopdf
A Rust library for PDF document manipulation.
Example Code
- Create PDF document
extern crate lopdf;
use ;
use ;
let mut doc = with_version;
let pages_id = doc.new_object_id;
let font_id = doc.add_object;
let resources_id = doc.add_object;
let content = Content ;
let content_id = doc.add_object;
let page_id = doc.add_object;
let pages = dictionary! ;
doc.objects.insert;
let catalog_id = doc.add_object;
doc.trailer.set;
doc.compress;
doc.save.unwrap;
- Modify PDF document
let mut doc = load?;
doc.version = "1.4".to_string;
doc.replace_text;
doc.save?;
FAQ
-
Why keeping everything in memory as high-level objects until finally serializing the entire document?
Normally a PDF document won't be very large, ranging form tens of KB to hundreds of MB. Memory size is not a bottle neck for today's computer. By keep the whole document in memory, stream length can be pre-calculated, no need to use a reference object for the Length entry, the resulting PDF file is smaller for distribution and faster for PDF consumers to process.
Producing is a one-time effort, while consuming is many more.